package com.example.day7.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.day7.R;
import com.example.day7.bean.FuliBean;

import java.util.List;

import okhttp3.RequestBody;

public class FuliAdapter extends RecyclerView.Adapter<FuliAdapter.ViewHolder>{
    private Context context;
    private List<FuliBean.ResultsBean> data;

    public FuliAdapter(Context context, List<FuliBean.ResultsBean> data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.fuliitem, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        FuliBean.ResultsBean resultsBean = data.get(position);
        holder.tilte.setText(resultsBean.getDesc());
        Glide.with(context).load(resultsBean.getUrl()).into(holder.image);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView image;
        TextView  tilte;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            image=itemView.findViewById(R.id.imageView);
            tilte=itemView.findViewById(R.id.textView);
        }
    }
}
